<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加商品</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/extends/AmazeUI-2.7.2/css/amazeui.css">
    <link href="__STATIC__/css/base.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="__STATIC__/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/layuiadmin/style/admin.css" media="all">

    <script type="text/javascript" src="__STATIC__/js/jquery-1.11.3.min.js"></script>
    <script src="__STATIC__/extends/AmazeUI-2.7.2/js/amazeui.min.js"></script>

    <link rel="stylesheet" href="__STATIC__/css/seller.css">
    <link rel="stylesheet" href="__STATIC__/css/member.css">
    <link rel="stylesheet" href="__STATIC__/css/seller_goods.css">
    <script src="__STATIC__/js/common.js"></script>

</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">添加商品</div>
        
        <div class="layui-card-body" style="padding: 15px;">
            {if $info}
            <form method="post" action="{:url('editPost')}" class="layui-form">
                <input type="hidden" name="id" value="{$info.id}"/>
            {else /}
            <form method="post" action="{:url('addPost')}" class="layui-form"  enctype="multipart/form-data">
            {/if}


                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class="red">*</span> 商品名称：</label>
                    <div class="layui-input-block formControls">
                        <input type="text" onBlur="" id="goods_name" lay-verify="title" autocomplete="off" placeholder="商品名称名称不能为空！"  name="goods_name" class="layui-input">
                        <span class="Validform_checktip"></span>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label"><span class="red">*</span>商品分类：</label>
                    <div class="layui-input-inline">
                        <select name="goodscateid"  lay-verify="required" >
                            <option  value="0">请选择商品分类</option>

                            {volist name="goodscate" id="vo"}
                            <option value="{$vo['gcate_id']}">{$vo.goodscatename|raw}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div style="margin-top: 2%"></div>
                <div class="layui-form-item">
                    <label class="layui-form-label">模板等级：</label>
                    <div class="layui-input-block formControls">
                        <input type="text"  id="softsize" lay-verify="title" autocomplete="off" placeholder="模板等级！" name="softsize" class="layui-input">
                        <span class="Validform_checktip"></span>
                    </div>
                </div>
                {volist name="attrinfo" id="vo"}

                <div class="layui-inline">
                    <label class="layui-form-label" style="margin-top:8px"><span class="red">*</span>{$vo['group_name']}：</label>
                    <div class="layui-input-inline" style="margin-top:10px">
                        <select name="{$vo['screenid']}"  lay-verify="required" >
                            <option  value="0">请选择详情模版</option>
                            {if  $vo.son neq null}
                            {volist name="vo.son" id="voson"}
                            <option  value="{$voson['type_id']}">{$voson['type_name']}</option>
                            {/volist}
                            {/if}
                        </select>
                    </div>
                </div>

                {/volist}
                <div style="margin-top: 2%"></div>
                {volist name="layouinfo" id="vo"}
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*</span>{$vo['group_name']}:</label>
                    <div class="layui-input-block">
                        {if  $vo.son neq null}
                        {volist name="vo.son" id="voson"}
                        <input type="checkbox" value="{$voson['type_id']}" name="{$vo['screenid']}[]" title="{$voson['type_name']}">
                        {/volist}
                        {/if}
                    </div>
                </div>

                {/volist}

                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*</span>售价</label>
                    <div class="layui-input-block delivery" id="spec_price_tab">

                        <strong class="change current">
                            <input name="is_spec" type="radio" value="0" id="is_spec" class="is_spec" checked="" title="一口价" autocomplete="off">
                            <div class="layui-unselect layui-form-radio layui-form-radioed">
                                <i class="layui-anim layui-icon layui-anim-scaleSpring"></i>
                                <div>一口价</div>
                            </div>
                        </strong>
                        <strong class="change">
                            <input name="is_spec" type="radio" value="1" id="is_spec" class="is_spec" title="套餐价格" autocomplete="off">
                            <div class="layui-unselect layui-form-radio">
                                <i class="layui-anim layui-icon"></i>
                                <div>套餐价格</div>
                            </div>
                        </strong>
                        <div class="change_box">
                            <div id="spec_auto_delivery" class="box" style="display: block;">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">一口价</label>
                                    <div class="layui-input-inline">
                                        <input class="layui-input" name="goods_price" value="" id="goods_price" maxlength="8" type="text">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">元 (不低于30元)</div>
                                </div>
                            </div>
                            <div id="spec_manual_delivery" class="box none" style="display: none;">
                                <div class="box" style="margin-top: -5px;">
                                    <table class="tablelist moneylist" style=" border-left:none;border-right:none; ">
                                        <thead>
                                        <tr>
                                            <td width="50%" style="border:0">套餐名称</td>
                                            <td width="30%" style="border:0">价格（元）</td>
                                            <td width="20%" style="border:0">操作</td>
                                        </tr>
                                        </thead>
                                        <tbody id="pkg-price-list" class="pkg-price-list">
                                      
                                        <tr class="pkg-price">
                                            
                                            <td>
                                                <input name="spec_name[]" class="layui-input t-label checkLen" d_len="8" placeholder="请输入套餐名称，不能超过20字符" maxlength="20" value="" type="text">
                                            </td>
                                            <td>
                                                <input name="spec_price[]" class="layui-input s o_number t-no  checkLen" placeholder="请输入套餐价格"  maxlength="8" d_len="4" value="" type="text">
                                            </td>
                                            <td><a class="del-price">删除</a></td>
                                        </tr>
                                       
                                        </tbody>
                                        <tfoot>
                                        <tr>
                                            <td colspan="4"><a class="addmoney">添加套餐</a></td>
                                        </tr>
                                        </tfoot>
                                    </table>
                                    <div class="notes">
                                        <li> <h3> 动态价格说明：</h3></li>
                                        <li><b>1.</b>【动态价格】最多可设置5条，至少需要设置1条；</li>
                                        <li><b>2.</b>【套餐名称】套餐名称默认最长20字符；</li>
                                        <li><b>3.</b>【套餐价格】不允许出现重复值，【价格】不低于30元；</li>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <label class="layui-form-label"></label>
                        <input type="hidden" name="goods_type" value="1">
                    </div>
                    <script>
                        $("#spec_price_tab").children(".change").click(function() {
                            var index = $(this).index();
                            $(this).addClass("current").siblings().removeClass("current");
                            if (index == 1) {
                                $("#spec_auto_delivery").hide();
                                $("#spec_manual_delivery").show();
                            } else {
                                $("#spec_auto_delivery").show();
                                $("#spec_manual_delivery").hide();
                            }
                        })
                        //添加一口价套餐价格
                        $(document).on('click','.del-price',function(){
                            if($(".moneylist tbody tr").size()>1){
                                $(this).parent().parent().remove();
                            }
                        });
                        //添加套餐价格
                        $(".addmoney").click(function () {
                            var length = $(".moneylist tbody tr").length;
                            if(length < 5 ){
                                var html = ' <tr class="pkg-price"><td><input name="spec_name[]" class="layui-input t-label checkLen" placeholder="请输入套餐名称，不能超过20字符" d_len="8" maxlength="20" value="" type="text"></td>';
                                html += '<td><input name="spec_price[]" class="layui-input s o_number t-no checkLen" placeholder="请输入套餐价格" onkeyup="this.value= this.value.match(/\\d+(\\.\\d{0,2})?/) ? this.value.match(/\\d+(\\.\\d{0,2})?/)[0] : \'\'"  maxlength="8" d_len="4" value="" type="text"></td>';
                                html += '<td><a  class="del-price"   >删除</a></td> </tr>';
                                $(".moneylist tbody ").append(html);
                            }else{
                                layer.msg("亲,不能添加了");
                            }
                        });


                    </script>


                </div>



                <div class="layui-form-item">
                    <label class="layui-form-label">描述：</label>
                    <div class="layui-input-block">
                        <textarea  autocomplete="off" lay-verify="description" name="desc"  placeholder="描述不能少于20个字符" class="layui-textarea" ></textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-from-label"><i class="must">*</i>商品详情</div>
                    <div class="layui-input-block">
                        <textarea id="ueditor" name="gcontent" type="text/plain"></textarea>
                    </div>
                </div>



                <div class="layui-form-item">
                    <label class="layui-form-label">封面图:</label>
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" id="image">
                            <i class="layui-icon">&#xe60d;</i>上传图片
                        </button>
                    </div>
                    <div class="layui-input-block" style="margin-top: 3px">
                        <img src="{$info.image?$info.image:'__STATIC__/images/011.jpg'}" style="width: 150px" alt="" id="image_thumb">
                        <input type="hidden" name="image" value="{$info['image']}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">演示网址</label>
                    <div class="layui-input-inline">
                        <input id="demo_url"  name="demo_web" class="layui-input" style="width:400px" maxlength="100"  type="text" autocomplete="off" placeholder="必须以http(s)开头" />
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="Validform_checktip"></span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">是否启用：</label>
                    <div class="layui-input-block">
                        <input type="radio" name="goods_status" value="1" checked title="是" >
                        <input type="radio" name="goods_status" value="0"  title="否">
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" lay-submit="" id="btn" lay-filter="component-form-demo1">立即提交</button>
                            <a href="{:url('goods/index')}" class="layui-btn layui-btn-primary">返回</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="__STATIC__/extends/js/jquery-ui.js"></script>
<script type="text/javascript" src="__STATIC__/extends/ueditor/1.4.3/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__STATIC__/extends/ueditor/1.4.3/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('ueditor', {
        initialFrameHeight: 500,
        initialFrameWidth: 'auto',
    });
</script>

<script src="__STATIC__/extends/layui2.4.5/layui.all.js "></script>
<script src="__STATIC__/extends/Validform/5.3.2/Validform.min.js "></script>

<script type="text/javascript">
    $(function() {
        //表单验证
        $("form").Validform({
            tiptype:function(msg,o,cssctl){
                if(!o.obj.is("form")){
                    //默认表单
                    var objtip=o.obj.parents(".formControls").find(".Validform_checktip");
                    cssctl(objtip,o.type);
                    objtip.text(msg);
                }
            },
            showAllError:true
        })

    });
</script>
<script src="__STATIC__/layuiadmin/layui/layui.js"></script>
<script>

    layui.use(['form', 'upload'], function () {
        var upload = layui.upload;
        upload_img('image');
        function upload_img (id) {
            //选完文件后自动上传
            upload.render({
                elem: '#'+id,
                url: "{:url('UpFiles/uploadadmin')}",
                auto: true,
                accept: 'file', //普通文件
                data :{type:id,name:'file'},
                before: function (obj) {
                    var img_url = $('input[name='+id+']').val();
                    // 删除老数据
                    if (img_url != '') {
                        $.ajax({
                            url: "{:url('UpFiles/delImg')}",
                            type: 'POST',
                            data: {
                                img_url: img_url
                            },
                        });
                    }
                    //本地本地预览示例
                    obj.preview(function(index,file,result){
                        $("#"+id+"_thumb").attr('src',result).show();
                    });
                },
                done: function (res) {
                    //上传完毕回调
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    } else {
                        $("#"+id+"_thumb").attr('src',res.data.src).show();
                        $('input[name='+id+']').val(res.data.src);
                    }
                }
            });
        }
    });

</script>

<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form
            ,upload = layui.upload;

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#LAY-component-form-group-date'
        });


    });

    layui.use(['form'], function() {
        var form = layui.form; //日期
        form.on('checkbox(checkbox)', function(data){
            var key = $(data.elem).attr("key");
            if(data.elem.checked === true){
                $("."+key).show();
            }else{
                $("."+key).hide();
            }
        });

    })

</script>
<script>
    $(function() {
        //剪切插件

        //安装服务切换
        $("#installing").children("strong").click(function() {
            var index = $(this).index();
            $(this).addClass("current").siblings().removeClass("current");
            if (index == 1) {
                $("#install_money").show();
            } else {
                $("#install_money").hide();
            }
        })
        //发货方式切换
        $("#delivery_area").children(".change").click(function() {
            var index = $(this).index();
            $(this).addClass("current").siblings().removeClass("current");
            if (index == 1) {
                $("#auto_delivery").hide();
                $("#manual_delivery").show();
            } else {
                $("#auto_delivery").show();
                $("#manual_delivery").hide();
            }
        })

    });
</script>
</body>
</html>